<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>增加</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.css">
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
    <style>
      .modal-body{
        margin:0 auto;
        width: 20%;
      }
      .modal-footer{
        text-align: center;
      }
    </style>
  </head>
  <body>
    <div class="modal-body">
      <form>
        <div class="form-group">
          <label for="title">标题：</label>
          <input type="text" name="title" id="title" />
        </div>
        <div class="form-group">
          <label for="content">内容：</label>
          <input type="text" name="content" id="content" />
        </div>
        <div class="modal-footer">
          <button id="add"  class="btn btn-primary">提交</button>
        </div>
      </form>
    </div>
    
  </body>
</html>
<script>
  $(function() {
    $("#add").on("click", function() {
      var title = $("#title").val();
      var content = $("#content").val();
      $.post("./add.php", { title: title, content: content }, function(res) {
        console.log(res.msg)
        if (res.msg == "ok") {
          alert("添加成功");
          window.location.href = "index.html";
        }
      },'json');
    });
  });
</script>
